package com.sky.task;

import com.sky.entity.Orders;
import com.sky.mapper.OrderMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * 订单任务
 *
 * @author iTaotao
 * @version 1.0
 * @date 2023/08/07 09:44:49
 */
@Slf4j
@Component
public class OrderTask {

    @Autowired
    private OrderMapper  orderMapper;
    @Scheduled(cron = "0 0/1 * * * ? ")
    public void orderTimeOut(){
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime time = now.plusMinutes(-15);

        Integer count = orderMapper.updateStatusByStatusAndBeforeOrderTime(Orders.CANCELLED ,Orders.PENDING_PAYMENT , time);
        log.info("订单影响的行数: {}",count);
    }

    @Scheduled(cron ="0 0/1 * * * ? " )
    public void Order(){
     Integer count = orderMapper.updateStatuByStatus( Orders.COMPLETED,Orders.DELIVERY_IN_PROGRESS );
     log.info("影响行数:{}",count);

    }
}
